/**
 * Created by novem on 15/9/25.
 */
window.onload=function(){
    var url = getUrl();
    $(".ui-header-right").on("click", function () {
        var star= $("#star li.on").length;
        var comment = $("#comment").val();
        var urlList = getPics();

        var photobookId= $.getUrlParam("photobookId");
        var userId = getUserId();
        if(star == 0){
            showToast("总体评价需要打分哦~");
            return;
        }


        if(comment == ""){
             showToast("点评内容不能为空哦~");
             return;
        }

        $.jsonp({
            url: 'http://'+url+'/api/photobook/comment',
            data: {star:star,comment:comment,photobookId:photobookId,urlList:urlList,userId:userId},
            callbackParameter: "callback",
            success: function (data, textStatus, xOptions) {
                if(data.succ==true){
                    showToast("评论成功~");
                    window.history.go(-1);
                }
            },
            error: function (xOptions, textStatus) {
            showToast("评论失败~");
            }
        });
    });
    var oStar = document.getElementById("star");
    var aLi = oStar.getElementsByTagName("li");
    var oUl = oStar.getElementsByTagName("ul")[0];
    for (i = 1; i <= aLi.length; i++){
        aLi[i - 1].index = i;
        //鼠标移过显示分数
        aLi[i - 1].onmouseover = function (){
            fnPoint(this.index);
        };
    }
    //评分处理
    function fnPoint(iArg){
        //分数赋值
        iScore = iArg ;
        for (i = 0; i < aLi.length; i++) aLi[i].className = i < iScore ? "on" : "";
    }

//    function getPics(){
//        var imgs=$(".ppt img");
//        var paths=[];
//        $.each(imgs,function(index,ele){
//            paths.push($(ele).attr('src'));
//        })
//        var paths=paths.join(",");
//        return paths;
//    }
}
